package servlets;

import java.util.Date;


public class Notification
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//-- Application notifications up to 0
	private static  String logDir = "/tmp/WorkplacementManagementSystem/Logs/";
	public static  String DiaryDir = "/tmp/WorkplacementManagementSystem/Diary/";
	private static  String appliLog = "/application.log";
	public static int file_read = 0;
	public static int file_write = 1;
	public static int md5Algo = 2;
	public static int file_delete_error = 3;
	public static int file_unexist = 4;
	public static int appl_password_wrong = 5;
	public static int appl_identification = 6;
	
	
	
	//-- User notifications up to 100
	private static String userLog = "user.log";
	public static int login_password_wrong = 100;
	public static int password_wrong = 101; //--only in the page after login
	public static int password_2_error = 102;
	public static int logout = 103;
	public static int logged = 104;
	
	
	//-- Admin notifications up to 200
	private String adminLog = "admin.log";
	
	//-- Student notifications up to 300
	private static String studentLog = "student.log";
	public static int cv_not_pdf = 300;
	public static int password_student_ok = 301;
	public static int password_student_length = 302;
	public static int  mail_student_ok = 303;
	public static int  mail_student_exp = 304;
	public static int dirCVBuilt = 305;
	public static int cv_ok = 306;
	public static int cv_upload_error = 307;
	public static int cv_delete = 308;
	public static int cv_delete_error = 309;
	public static int no_academic_sup = 310;
	public static int no_company_sup = 311;
	public static int no_cv = 312;
	public static int diary_empty = 313;
	public static int timetable_empty = 314;
	public static int timetable_event = 315;
	public static int timetable_multipe_event = 316;
	public static int timetable_date_empty = 317;
	public static int timetable_event_delete_error = 318;
	public static int timetable_decriptor_error = 319;
	public static int timetable_event_edit_error = 320;
	public static int timetable_event_date1_sup_error = 321;
	public static int comp_pref_save_error1 = 322;
	public static int comp_pref_save_error2 = 323;
	public static int comp_pref_save_error3 = 324;
	public static int comp_pref_del_error1 = 325;
	public static int comp_pref_del_error2 = 326;
	public static int comp_pref_del_error3 = 327;
	public static int comp_pref_nomatch = 328;
	public static int comp_pref_saveComp_error = 329;
	public static int comp_pref_delCompPref_error = 330;
	public static int comp_pref_noSet = 331;
	public static int comp_pref_choose = 332;
	public static int comp_pref_no_choose = 333;
	public static int comp_pref_favourite_delete_all= 334;
	public static int query_not_sent = 335;
	public static int query_sentList_empty = 336;
	public static int query_delete_error = 337;
	public static int offer_list_empty = 338;
	public static int offer_persolist_empty = 339;
	public static int offer_apply_error = 340;
	public static int offer_accept_error = 341;
	public static int offer_reject_error = 342;
	
	//-- Carrer notifications up to 400
	private static String careerLog = "career.log";
	public static int password_career_ok = 401;
	public static int password_career_length = 402;
	public static int  mail_career_ok = 403;
	public static int  mail_career_exp = 404;
	public static int  career_createCompany_error = 405;
	public static int  career_createRecruiter_error = 406;
	public static int  career_createSupervisor_error = 407;
	public static int  career_createOffer_error = 408;
	public static int  career_no_recruiter = 409;
	public static int  career_no_supervisor = 410;
	public static int  career_no_offer = 411;
	public static int  career_no_comSelect = 412;
	public static int  career_updateCompany_error = 413;
	public static int  career_updateRecruiter_error = 414;
	public static int  career_updateSupervisor_error = 415;
	public static int  career_updateOffer_error = 416;
	public static int  career_deleteCompany_error = 417;
	public static int  career_deleteRecruiter_error = 418;
	public static int  career_deleteSupervisor_error = 419;
	public static int  career_deleteOffer_error = 420;
	public static int  career_noStudent = 421;
	public static int  career_noDegree = 422;
	public static int career_no_studentFeedback = 423;
	public static int career_no_degreeFeedback = 424;
	
	//-- Marker notifications up to 500
	
	//-- Companies notifications up to 600
	private static String companyLog = "company.log";
	public static int no_company = 600;
	public static int company_notFound = 601;
	
	//-- AcademicSup notifications up to 700
	private static String AcademicSupLog = "academicSup.log";
	public static int no_academicSup = 700;
	
	//-- Query notifications up to 800
	private static String QueryLog = "queries.log";
	public static int query_no_academicSup = 800;
	
	public Notification()
	{}
	
	public static String getNotification(int errorNB,String login)
	{	
		String txt = "";
		String appl = ""; 
		switch(errorNB)
        {
        	case 0:
        		txt = "[ERROR]: Cannot read the file.";
        		writeLog(login,txt,appliLog);
            	break;
        	case 1:
            	txt = "[ERROR]: Cannot write the file.";
                writeLog(login,txt,appliLog);
                break;
        	case 2:
            	txt = "[INTERNAL ERROR]: Cannot check the password.";
            	appl = "[INTERNAL ERROR]: Problem with the Md5Encryption class.";
                writeLog(login,appl,appliLog);
                break;
        	case 3:
            	appl = "[INTERNAL ERROR]: Cannot delete the file.";
                writeLog(login,appl,appliLog);
                break;
        	case 4:
            	appl = "[INTERNAL ERROR]: Cannot find the file.";
                writeLog(login,appl,appliLog);
            break;
        	case 5:
            	appl = "[ERROR]: User not find.";
                writeLog(login,txt,userLog);
                break;
        	case 6:
            	txt = "[ERROR]: You need to be log in to access to this page";
                writeLog(login,txt,userLog);
                break;
            case 100:
            	txt = "[ERROR]: Incorrect Login and/or Password.";
                writeLog(login,txt,userLog);
                break;
            case 101:
            	txt = "[ERROR]: The password, that you provide, didn't match with the one you registered.";
            	break;
            case 102:
            	txt = "[ERROR]: The two new passwords, that you type, are not the same.";
            	break;
            case 103:
            	txt = "[APPLICATION]: You have been successfully log out. Thank you for using the system";
            	writeLog(login,txt,userLog);
            case 104:
            	appl = "[APPLICATION]: User logged in";
            	writeLog(login,appl,userLog);
            	break;
            case 300:
            	txt = "[ERROR]: Uploaded files must be in PDF format.";
            	break;
            case 301:
            	txt = "New password registered.";
                writeLog(login,txt,studentLog);
                break;
            case 302:
            	txt = "[ERROR]: A password must be at least 5 characters long.";
            	break;
            case 303:
            	txt = "New email address registered.";
                writeLog(login,txt,studentLog);
                break;
            case 304:
            	txt = "[ERROR]: Wrong email address format. Email addresses must look like : \"abc@abc.com\".";
            	break;
            case 305:
        		appl = "[DIR]: CV Directory built.";
                writeLog(login,appl,appliLog);
                break;
            case 306:
            	txt = "CV has been successfully saved.";
                writeLog(login,txt,studentLog);
                break;
            case 307:
            	txt = "[ERROR]: Upload Failed.";
            	appl = "[INTERNAL ERROR]: Problem with the uploadCV in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 308:
            	txt = "[DEL]: CV deleted.";
                writeLog(login,txt,studentLog);
                break;
            case 309:
            	txt = "[ERROR]: Delete Failed.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteCV in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 310:
            	txt = "You don't have yet an Academic Supervisor. If you already have an offer, please select an Academic Supervisor and send her/him a query.";
            	break;
            case 311:
            	txt = "You don't have yet a Company Supervisor. You need to accept an offer and wait for the answer of the company to know your Company Supervisor.";
            	break;
            case 312:
            	txt = "You didn't upload CVs in the system.";
            	break;
            case 313:
            	txt = "Your placement diary is empty.";
            	break;
            case 314:
            	txt = "You have not yet plan events.";
            	break;
            case 315:
            	txt = "[INTERNAL ERROR]: The system is unabled to event.";
            	appl = "[INTERNAL ERROR]: Problem with the addEvent in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 316:
            	txt = "[INTERNAL ERROR]: The system is unabled to add multiple events.";
            	appl = "[INTERNAL ERROR]: Problem with the addMultipleEvent in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 317:
            	txt = "The date \"Start\" needs at least to be fill to add an event.";
            	break;
            case 318:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete event.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteEvent in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 319:
            	txt = "[INTERNAL ERROR]: The system is unabled to to find event.";
            	appl = "[INTERNAL ERROR]: Problem with the editEvent in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 320:
            	txt = "[INTERNAL ERROR]: The system is unabled to edit event.";
            	appl = "[INTERNAL ERROR]: Problem with the editedEvent in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 321:
            	txt = "[ERROR]: The date \"Start\" should be before the date \"End\".";
            	break;
            case 322:
            	txt = "[INTERNAL ERROR]: The system is unabled to save your preferences.";
            	appl = "[INTERNAL ERROR]: Problem with the setSectorPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 323:
            	txt = "[INTERNAL ERROR]: The system is unabled to save your preferences.";
            	appl = "[INTERNAL ERROR]: Problem with the setCityPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 324:
            	txt = "[INTERNAL ERROR]: The system is unabled to save your preferences.";
            	appl = "[INTERNAL ERROR]: Problem with the setCountryPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 325:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete your preferences.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteSectorPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 326:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete your preferences.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteCityPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 327:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete your preferences.";
            	appl = "[INTERNAL ERROR]: Problem with the setCountryPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 328:
            	txt = "[ERROR]: Any company in the database matches with your preferences.";
            	break;
            case 329:
            	txt = "[INTERNAL ERROR]: The system is unabled to select this company as one of your favourite companies.";
            	appl = "[INTERNAL ERROR]: Problem with the setCompaniesPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 330:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete this company from your favourite companies.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteCompaniesPref in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 331:
            	txt = "You have not set yet your preferences.";
            	break;
            case 332:
            	txt = "You have to select your favourite company from the list of relevant companies. Press the button \"View Relevant Companies\"";
            	break;
            case 333:
            	txt = "You should select at least one preference or press \"Back\" (or \"Preference\" on the left menu) to go in the main companies preference menu.";
            	break;
            case 334:
            	txt = "All favourite companies have been deleted.";
            	break;
            case 335:
            	txt = "[INTERNAL ERROR]: The system is unabled to send your query.";
            	appl = "[INTERNAL ERROR]: Problem with the sendQuery in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
            case 336:
            	txt = "You have not yet sent any queries.";
            	break;
            case 337:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete this query.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteQuery in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
            case 338:
            	txt = "Currently, the system have any offer registered.";
            	break;
            case 339:
            	txt = "You haven't applied for an offer or you have not yet received a personnal offer.";
            	break;
            case 340:
            	txt = "[INTERNAL ERROR]: The system is unabled to apply for this offer.";
            	appl = "[INTERNAL ERROR]: Problem with the acceptOffer in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 341:
            	txt = "[INTERNAL ERROR]: The system is unabled to accept this offer.";
            	appl = "[INTERNAL ERROR]: Problem with the acceptOffer in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 342:
            	txt = "[INTERNAL ERROR]: The system is unabled to reject this offer.";
            	appl = "[INTERNAL ERROR]: Problem with the rejectOffer in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 401:
            	txt = "New password registered.";
                writeLog(login,txt,careerLog);
                break;
            case 402:
            	txt = "[ERROR]: A password must be at least 5 characters long.";
            	break;
            case 403:
            	txt = "New email address registered.";
                writeLog(login,txt,careerLog);
                break;
            case 404:
            	txt = "[ERROR]: Wrong email address format. Email addresses must look like : \"abc@abc.com\".";
            	break;
            case 405:
            	txt = "[INTERNAL ERROR]: The system is unabled to create this company.";
            	appl = "[INTERNAL ERROR]: Problem with the createCompany in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 406:
            	txt = "[INTERNAL ERROR]: The system is unabled to create this recruiter.";
            	appl = "[INTERNAL ERROR]: Problem with the createRecruiter in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 407:
            	txt = "[INTERNAL ERROR]: The system is unabled to create this supervisor.";
            	appl = "[INTERNAL ERROR]: Problem with the createSupervisor in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 408:
            	txt = "[INTERNAL ERROR]: The system is unabled to create this offer.";
            	appl = "[INTERNAL ERROR]: Problem with the createOffer in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 409:
            	txt = "Currently, this company have any company recruiter registered.";
            	break;
            case 410:
            	txt = "Currently, this company have any company supervisor registered.";
            	break;
            case 411:
            	txt = "Currently, this company have any offer registered.";
            	break;
            case 412:
            	txt = "You have not select a company to perform an \"Add action\".";
            	break;
            case 413:
            	txt = "[INTERNAL ERROR]: The system is unabled to update this company.";
            	appl = "[INTERNAL ERROR]: Problem with the updateCompany in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 414:
            	txt = "[INTERNAL ERROR]: The system is unabled to update this recruiter.";
            	appl = "[INTERNAL ERROR]: Problem with the updateRecruiter in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 415:
            	txt = "[INTERNAL ERROR]: The system is unabled to update this supervisor.";
            	appl = "[INTERNAL ERROR]: Problem with the updateSupervisor in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 416:
            	txt = "[INTERNAL ERROR]: The system is unabled to update this offer.";
            	appl = "[INTERNAL ERROR]: Problem with the updateOffer in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 417:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete this company.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteCompany in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 418:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete this recruiter.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteRecruiter in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 419:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete this supervisor.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteSupervisor in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 420:
            	txt = "[INTERNAL ERROR]: The system is unabled to delete this offer.";
            	appl = "[INTERNAL ERROR]: Problem with the deleteOffer in CareerSessionBean class.";
                writeLog(login,appl,careerLog);
                writeLog("CareerServlet",appl,appliLog);
                break;
            case 421:
            	txt = "Currently, the system have any student registered.";
            	break;
            case 422:
            	txt = "Currently, the system have any degree registered.";
            	break;
            case 423:
            	txt = "Currently, this student have any feedback loaded in the system.";
            	break;
            case 424:
            	txt = "Currently, this degree have any feedback loaded in the system.";
            	break;
            case 600:
            	txt = "Currently, the system have any company registered.";
            	break;
            case 601:
            	txt = "[INTERNAL ERROR]: Request failed. The system is not able to find the selected company.";
            	appl = "[INTERNAL ERROR]: Problem with the getCompany in StudentSessionBean class.";
                writeLog(login,txt,studentLog);
                writeLog("StudentServlet",appl,appliLog);
                break;
            case 700:
            	txt = "Currently, the system have any academic supervisor registered.";
            	break;
            case 800:
            	txt = "Currently, the system have any academic supervisor registered. So you cannot send a query.";
            	appl = "[QUERY]: Cannot send queries, no academic supervisor in the system.";
                writeLog("",appl,studentLog);
            	break;
            default:
            	txt = "[ERROR]: Undefined error.";
            	writeLog(login,txt,appliLog);
            	break;
        }
		
		return txt;
	}
	
	public static void writeLog(String login, String txt, String log)
	{
		WriteReadFile writer = new WriteReadFile();
		Date date = new Date();
		String towrite = date.toString() + " - " + login + " - " + txt;
		writer.write(towrite, logDir, log);
	}
}

